//
//  DebtTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/7.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class DebtTableViewCell: UITableViewCell {
    @IBOutlet weak var orderNumber: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var money: UILabel!
    
    var model:DebtDetailModel!
    
    var backClosure:TouchBlock!
    
    lazy var alertView : AlertContentView = {
        let view = AlertContentView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.ScreenWidth, height: UIScreen.ScreenHeight))
        
        view.backClosure = { [weak self] in
            self?.userSettleArrears()
        }
        
        UIApplication.shared.keyWindow?.addSubview(view)
        return view
    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    // MARK:归还欠款
    @IBAction func btnClick(_ sender: UIButton) {
        self.alertView.show(withTitle: "确定要归还欠款吗？")
    }
    
    func userSettleArrears(){
        PKhud.show()
        HttpRequest.requestData(.post, URLString: Api.userSettleArrears.rawValue, parameters: ["orderId":self.model.id]) { (result) in
            PKhud.hiden()
            if result["msg"] as! String == "success"{
                if self.backClosure != nil {
                    self.backClosure()
                }
            }else{
                PKhud.showText(text: result["data"] as! String)
            }
        }
    }
    
    func reload(withModel model:DebtDetailModel){
        self.model = model
        self.orderNumber.text = "订单号：" + model.number
        self.timeLabel.text = "结算时间：" + model.modifyTime.timeStampToString(timeFormat: "YYYY-MM-dd HH:mm:ss")
        let str = "￥" + model.arrears + "元"
        self.money.attributedText = Utils.changeLabelTextFontSize(normalString: str, changeString: model.arrears.getPriceInteger(), font: UIFont.systemFont(ofSize: 16))
    }
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
